package ukoly;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import uzivatele.Uzivatel;
        

/**
 *
 * @author Pavel Lieberzeit
 */
public class ProjektModel {
    
    final private int ID;
    private String jmeno;
    private String popis;
    
    private GregorianCalendar casStart;
    
    private GregorianCalendar casKonec;
    
    private GregorianCalendar casDead; //deadline   
    
    private int casStraven; //should be in hours
    
    private Uzivatel odpovedny;
    
    private UkolStatus status;


    /**
     * konstruktor pro vytvoreni noveho projektu
     * @param ID
     * @param jmeno
     * @param popis
     * @param deadline
     * @param odpovedny
     * @param status 
     */
    public ProjektModel(int ID, String jmeno, String popis, GregorianCalendar deadline, Uzivatel odpovedny,
            UkolStatus status, int casStraven) {
        
        this(ID, jmeno, popis, new GregorianCalendar(), null, deadline, casStraven, odpovedny, status );
        
        this.casStart.setTime(new Date(System.currentTimeMillis()));
    }

    /**
     * Konstruktor pro pouziti pri nacteni z databaze
     * @param ID
     * @param jmeno
     * @param popis
     * @param casStart
     * @param casKonec
     * @param deadline
     * @param casStraven
     * @param odpovedny
     * @param status 
     */
    public ProjektModel(int ID, String jmeno, String popis, GregorianCalendar casStart, GregorianCalendar casKonec, 
            GregorianCalendar deadline, int casStraven, Uzivatel odpovedny, UkolStatus status) {
        
        this.ID = ID;
        this.jmeno = jmeno;
        this.popis = popis;

        this.casDead = deadline;
        this.casKonec = casKonec;
        this.casStart = casStart;

        this.casStraven = casStraven;

        this.odpovedny = odpovedny;
        this.status = status;
    
    }
    
    public int getID() {
        return ID;
    }

    public GregorianCalendar getCasDead() {
        return casDead;
    }

    public GregorianCalendar getCasKonec() {
        return casKonec;
    }

    public GregorianCalendar getCasStart() {
        return casStart;
    }

    public int getCasStraven() {
        return casStraven;
    }

    public String getJmeno() {
        return jmeno;
    }

    public Uzivatel getOdpovedny() {
        return odpovedny;
    }

    public String getPopis() {
        return popis;
    }

    public UkolStatus getStatus() {
        return status;
    }

    public void setCasDead(GregorianCalendar casDead) {
        this.casDead = casDead;
    }

    public void setCasKonec(GregorianCalendar casKonec) {
        this.casKonec = casKonec;
    }

    public void setCasStraven(int casStraven) {
        this.casStraven = casStraven;
    }

    public void setJmeno(String jmeno) {
        this.jmeno = jmeno;
    }

    public void setOdpovedny(Uzivatel odpovedny) {
        this.odpovedny = odpovedny;
    }

    public void setPopis(String popis) {
        this.popis = popis;
    }

    public void setStatus(UkolStatus status) {
        this.status = status;
    }


    /**
     * Technicka poznamka - v praktickem vyuziti by se equals nemelo skoro pouzit, protoze
     * jediny rozpoznavaci atribut je ID. Udaje se uvnitr programu neukladaji a posilaji/nacitaji se do databaze
     * Equals doesn't include times, sadly - too little time
     * Not uzivatel either, because of loops
     * TODO look up here
     * @param obj
     * @return 
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ProjektModel other = (ProjektModel) obj;
        if (this.ID != other.ID) {
            return false;
        }
        if ((this.jmeno == null) ? (other.jmeno != null) : !this.jmeno.equals(other.jmeno)) {
            return false;
        }
        if ((this.popis == null) ? (other.popis != null) : !this.popis.equals(other.popis)) {
            return false;
        }
//        if (this.casStart != other.casStart && (this.casStart == null || (this.casStart.get(Calendar.YEAR)==other.casStart.get(Calendar.YEAR) &&
//                this.casStart.get(Calendar.MONTH)==other.casStart.get(Calendar.MONTH) && this.casStart.get(Calendar.DAY_OF_MONTH)==other.casStart.get(Calendar.DAY_OF_MONTH)))) {
//            return false;
//        }
//        if (this.casKonec != other.casKonec && (this.casKonec == null || (this.casKonec.get(Calendar.YEAR)==other.casKonec.get(Calendar.YEAR) &&
//                this.casKonec.get(Calendar.MONTH)==other.casKonec.get(Calendar.MONTH) && this.casKonec.get(Calendar.DAY_OF_MONTH)==other.casKonec.get(Calendar.DAY_OF_MONTH)))) {
//            return false;
//        }
//        if (this.casDead != other.casDead && (this.casDead == null || (this.casDead.get(Calendar.YEAR)==other.casDead.get(Calendar.YEAR) &&
//                this.casDead.get(Calendar.MONTH)==other.casDead.get(Calendar.MONTH) && this.casDead.get(Calendar.DAY_OF_MONTH)==other.casDead.get(Calendar.DAY_OF_MONTH)))) {
//            return false;
//        }
        if (this.casStraven != other.casStraven) {
            return false;
        }
        if (this.status != other.status && (this.status == null || !this.status.equals(other.status))) {
            return false;
        }
        return true;
    }

    
    /**
     * Hashcode doesn't include time, sadly. Not uzivatel either, because of loops
     * TODO look up here
     * @return 
     */
    @Override
    public int hashCode() {
        int hash = 3;
        hash = 17 * hash + this.ID;
        hash = 17 * hash + (this.jmeno != null ? this.jmeno.hashCode() : 0);
        hash = 17 * hash + (this.popis != null ? this.popis.hashCode() : 0);
//        hash = 17 * hash + (this.casStart != null ? this.casStart.hashCode() : 0);
//        hash = 17 * hash + (this.casKonec != null ? this.casKonec.hashCode() : 0);
//        hash = 17 * hash + (this.casDead != null ? this.casDead.hashCode() : 0);
        hash = 17 * hash + this.casStraven;
        hash = 17 * hash + (this.status != null ? this.status.hashCode() : 0);
        return hash;
    }
    
    

}